﻿using System;
using System.Collections.Generic; 
using System.Text;
using ATSIDAL;
using ATSModel;
using System.Data.SqlClient;
using System.Data;

namespace ATSDAL
{
    public class AirtightnessConfigDal : BaseRepository_DT<AirtightnessConfigInfo>, IAirtightnessConfig
    {
        #region 静态变量部分
        private const string ARM_ID = "@ID";
        private const string ARM_PRODUCTTYPE_ID = "@ProductTypeID";
        private const string ARM_PRODUCTTYPE_CHANNELNO = "@ChannelNo";
        private const string ARM_PRODUCTTYPE_SPECVALUE = "@SpecValue";
        private const string ARM_PRODUCTTYPE_INFLATEDURATION = "@InflateDuration";
        private const string ARM_PRODUCTTYPE_BALANCEDURATION1 = "@BalanceDuration1";
        private const string ARM_PRODUCTTYPE_BALANCEDURATION2 = "@BalanceDuration2";
        private const string ARM_PRODUCTTYPE_MEASUREDURATION = "@MeasureDuration";
        private const string ARM_PRODUCTTYPE_LEAKSPEC = "@LeakSpec";
        private const string ARM_PRODUCTTYPE_MINUSLEAKSPEC = "@MinusLeakSpec";
        private const string ARM_PRODUCTTYPE_PRODUCTCUBAGE = "@ProductCubage";
        #endregion

        #region 数据检索部分

        /// <summary>
        /// 检索全部配置信息
        /// </summary>
        /// <returns></returns>
        public IList<AirtightnessConfigInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("sp_selAirtightnessConfig");
        }

        /// <summary>
        /// 根据S代码 检索配置信息
        /// </summary>
        /// <param name="productTypeID"></param>
        /// <returns></returns>
        public IList<AirtightnessConfigInfo> Airtightness_GetbyPID(string productTypeID)
        {
            SqlParameter parm = new SqlParameter(ARM_PRODUCTTYPE_ID, SqlDbType.NVarChar, 50);
            parm.Value = productTypeID;
            return ExcuteSqlToGetEntities("sp_selAirtightnessConfigbyProID", parm);
        }


        /// <summary>
        /// 根据ID 获取配置信息
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        public AirtightnessConfigInfo LoadEntity<T1>(T1 id)
        {
            SqlParameter parm = GetParameter();
            parm.Value = id;
            return ExcuteSqlToGetEntity("sp_selAirtightnessCofigbyID", parm);
        }

        /// <summary>
        /// 根据S 代码 和通道号检索配置信息
        /// </summary>
        /// <param name="productTypeID">S代码</param>
        /// <param name="channelNO">通道号</param>
        /// <returns>AirtightnessConfigInfo</returns>
        public AirtightnessConfigInfo Airtightness_GetbyPIDCHNO(string productTypeID, int channelNO)
        {
            SqlParameter[] parm = GetPPIDCHNOParameters(); 
            parm[0].Value = productTypeID;
            parm[1].Value = channelNO;
            return ExcuteSqlToGetEntity("sp_selAirtightnessConfigbyPIDCHNO", parm);
        }
        #endregion

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override AirtightnessConfigInfo GetEntityRecord(SqlDataReader rdr)
        {
            AirtightnessConfigInfo aro = new AirtightnessConfigInfo
            {
                ID = rdr.GetInt32(0),
                ProductTypeID = rdr.GetValue(1).ToString(),
                ChannelNo = rdr.GetInt32(2),
                SpecValue = rdr.GetInt32(3),
                InflateDuration = rdr.GetInt32(4),
                BalanceDuration1 = rdr.GetInt32(5),
                BalanceDuration2 = rdr.GetInt32(6),
                MeasureDuration = rdr.GetInt32(7),
                LeakSpec = rdr.GetInt32(8),
                MinusLeakSpec = rdr.GetInt32(9),
                ProductCubage = rdr.GetInt32(10)
            };
            return aro;
        }

        public override AirtightnessConfigInfo GetEntityRecord()
        {
            AirtightnessConfigInfo aro = new AirtightnessConfigInfo();
            return aro;
        }

        public override string GetInsertsp()
        {
            return "sp_InsertAirtightnessConfig";
        }

        public override string GetUpdatesp()
        {
            return "sp_UpdateAirtightnessConfig";
        }

        public override string GetDeletesp()
        {
            return "sp_DeleteAirtightnessConfig";
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(ARM_ID, SqlDbType.Int, 4);
            return Parm;
        }

        public SqlParameter[] GetPPIDCHNOParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(ARM_PRODUCTTYPE_ID, SqlDbType.NVarChar, 50),
					new SqlParameter(ARM_PRODUCTTYPE_CHANNELNO, SqlDbType.Int, 4)
                };
            return parms;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(ARM_ID, SqlDbType.Int, 4),
					new SqlParameter(ARM_PRODUCTTYPE_ID, SqlDbType.NVarChar, 50),
					new SqlParameter(ARM_PRODUCTTYPE_CHANNELNO, SqlDbType.Int, 4),
					new SqlParameter(ARM_PRODUCTTYPE_SPECVALUE, SqlDbType.Int, 4),
					new SqlParameter(ARM_PRODUCTTYPE_INFLATEDURATION, SqlDbType.Int, 4),
					new SqlParameter(ARM_PRODUCTTYPE_BALANCEDURATION1, SqlDbType.Int, 4),
					new SqlParameter(ARM_PRODUCTTYPE_BALANCEDURATION2, SqlDbType.Int, 4),
					new SqlParameter(ARM_PRODUCTTYPE_MEASUREDURATION, SqlDbType.Int, 4),
					new SqlParameter(ARM_PRODUCTTYPE_LEAKSPEC, SqlDbType.Int, 4),
					new SqlParameter(ARM_PRODUCTTYPE_MINUSLEAKSPEC, SqlDbType.Int, 4),
					new SqlParameter(ARM_PRODUCTTYPE_PRODUCTCUBAGE, SqlDbType.Int, 4),
                };
            return parms;
        }

        public override void SetParameters(AirtightnessConfigInfo airtConfig, params SqlParameter[] Parms)
        {
            Parms[0].Value = airtConfig.ID;
            Parms[1].Value = airtConfig.ProductTypeID;
            Parms[2].Value = airtConfig.ChannelNo;
            Parms[3].Value = airtConfig.SpecValue;
            Parms[4].Value = airtConfig.InflateDuration;
            Parms[5].Value = airtConfig.BalanceDuration1;
            Parms[6].Value = airtConfig.BalanceDuration2;
            Parms[7].Value = airtConfig.MeasureDuration;
            Parms[8].Value = airtConfig.LeakSpec;
            Parms[9].Value = airtConfig.MinusLeakSpec;
            Parms[10].Value = airtConfig.ProductCubage;
        }
        #endregion
    
    }
}
